import axios from 'axios'
const baseURL = '/api'
export const request = axios.create({
  baseURL,
  timeout: 5000
})

request.interceptors.request.use(
  (config) => {
    return config
  },
  (error) => {
    return Promise.reject(error)
  }
)

request.interceptors.response.use(
  (response) => {
    if (response.status === 200) {
      return response.data
    } else {
      return Promise.reject(new Error(response.statusText))
    }
  },
  (error) => {
    return Promise.reject(error)
  }
)

export default request
